<?php
header("Content-Type: text/html;charset=utf-8");

	include("../function/_nosql.php"); //

	include("../function/function.php");
	if(IS_AJAX){
		if($_GET['qian']=='dao'){
			$oid = chkstr(trim($_REQUEST['oid']));
			$uid = getClassName("kboy_order","uid","id=".$oid);
			$aid = getClassName("kboy_order","aid","id=".$oid);
			$allli = getClassName("kboy_forum_active","active_all_line","id=".$aid);
			$user_style = getClassName("kboy_user","user_style","uid=".$uid);
			$active_all_money = getClassName("kboy_forum_active","active_all_money","id=".$aid);
			$active_cva_money = getClassName("kboy_forum_active","active_cva_money","id=".$aid);
			$active_tian = getClassName("kboy_forum_active","active_tian","id=".$aid);
			$active_end_prov = getClassName("kboy_forum_active","active_end_prov","id=".$aid);
			$time = date('Y');
			if($active_cva_money == 0){
				$hdyouhui = $active_all_money;
			}else{
				$hdyouhui = $active_cva_money;
			}
			if(getClassName("kboy_order","order_qian","id=".$oid) == 1){
				$news_sql = "update kboy_order set order_qian=0 where id='$oid'";
				$news_rows = mysql_query($news_sql);
				$news_sql = "update kboy_user set user_activetime=user_activetime-1,user_km=user_km-".$allli." where uid='$uid'";
				$news_rows = mysql_query($news_sql);
				$news_sql = "update kboy_jiangli set hd_leiji=hd_leiji-1,hd_zong_jine=hd_zong_jine-".$active_all_money.",hdyouhui=hdyouhui-".$hdyouhui.",";
				if($active_tian < 3){
					$news_sql .= "hdduanxian=hdduanxian-1";
				}elseif($active_tian > 2 || $active_end_prov != '国外'){
					$news_sql .= "hdchangxian=hdchangxian-1";
				}elseif($active_end_prov == '国外'){
					$news_sql .= "hdguoji=hdguoji-1";
				}
				if($active_end_prov == '国外'){
					$news_sql .= ",hdguoji_jine=hdguoji_jin-".$active_cva_money;
				}
					$news_sql .= " where uid='$uid'";
					$news_res = mysql_query($news_sql);
				echo 3;die;
			}
			$news_sql = "update kboy_order set order_qian=1 where id='$oid'";
			$news_rows = mysql_query($news_sql);
			$news_sql = "update kboy_user set user_lasthd='$THIS_TODAY_DATETIME',user_activetime=user_activetime+1,user_km=user_km+".$allli." where uid='$uid'";
			$news_rows = mysql_query($news_sql);
			if($news_rows){
				if($user_style == 1){
					$news_sql = "select * from kboy_jiangli where uid='$uid' and hdnian='$time'";
					$news_rows = mysql_query($news_sql);
					$news_rs = mysql_fetch_array($news_rows);
					if($news_rs){
							//修改数据
							$news_sql = "update kboy_jiangli set hd_leiji=hd_leiji+1,hd_zong_jine=hd_zong_jine+".$active_all_money.",hdyouhui=hdyouhui+".$hdyouhui.",";
							if($active_tian < 3){
								$news_sql .= "hdduanxian=hdduanxian+1";
							}elseif($active_tian > 2 || $active_end_prov != '国外'){
								$news_sql .= "hdchangxian=hdchangxian+1";
							}elseif($active_end_prov == '国外'){
								$news_sql .= "hdguoji=hdguoji+1";
							}
							if($active_end_prov == '国外'){
								$news_sql .= ",hdguoji_jine=hdguoji_jine+".$active_cva_money;
							}
							$news_sql .= " where uid='$uid' and hd_jieshu=0";
							$news_res = mysql_query($news_sql);
							if($news_res){
								echo json_encode(1);
							}
						}else{
						// 添加数据
						$mysql = new sqlstr("kboy_jiangli");
						$mysql -> set("uid",$uid);
						$mysql -> set("hd_leiji",1);
						$mysql -> set("hd_zong_jine",$active_all_money);
						if($active_cva_money == 0){
						$mysql -> set("hdyouhui",$active_all_money);	
						}else{
							$mysql -> set("hdyouhui",$active_cva_money);
						}
						$mysql -> set("hdnian",$time);
						$mysql -> set("hdrenshu",$custom_power);
						if($active_tian < 3){
							$mysql -> set("hdduanxian",1);
						}elseif($active_tian > 2 || $active_end_prov != '国外'){
							$mysql -> set("hdchangxian",1);
						}elseif($active_end_prov == '国外'){
							$mysql -> set("hdguoji",1);
						}
						if($active_end_prov == '国外'){
							$mysql -> set("hdguoji_jine",$active_cva_money);
						}
						$news_sql = $mysql -> insertSql();
						$news_res = mysql_query($news_sql);
						if($news_res){
							echo json_encode(1);
						}
					}
				}else{
					echo json_encode(1); 
				}
			}else{
				echo json_encode(2); 
			}
		}
	}
?>